package edu.ccut.saturn.studio.wfg.wfgmodel;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Node;

import edu.ccut.saturn.studio.core.util.xml.SaturnW3CUtil;
import edu.ccut.saturn.studio.wfg.utils.RunTime;

public class LogicKeyAttribute implements SaturnAttribute{
	
	private String logicKey = "";
	
	private List<SaturnAttribute> attributes = new ArrayList<SaturnAttribute>();
	
	public LogicKeyAttribute(LogicKeyAttribute logicKeyAttribute){
		this.logicKey = logicKeyAttribute.logicKey;
		this.attributes = logicKeyAttribute.attributes;
	}
	
	public LogicKeyAttribute(){
	}
	
	// 适配器
	public String getKey() {
		return logicKey;
	}

	// 适配器
	public void setKey(String logicKey) {
		this.logicKey = logicKey;
	}
	
	public List<SaturnAttribute> getAttributes() {
		return attributes;
	}

	public void setAttributes(List<SaturnAttribute> attributes) {
		this.attributes = attributes;
	}

	public Node creatNode(Document doc, String nodeName) {
		Node logicNode = doc.createElement(nodeName);
		SaturnW3CUtil.createAttribute(logicNode, SaturnName.KEY_NODE_NAME_FULLKEY,RunTime.getValue(this, SaturnName.METHOD_GETKEY));
		createLogicKeyNodeList(doc, logicNode, this.getAttributes(), SaturnName.KEY_NODE_NAME_PARAMETER);
		return logicNode;
	}
	
	protected void createLogicKeyNodeList(Document document, Node node,
			List<SaturnAttribute> parameters, String nodeName){
		if(parameters.size()==0 || parameters == null){
			return;
		}
		for(SaturnAttribute parameter : parameters){
			Node parameterNode = createChildNode(document,parameter);
			node.appendChild(parameterNode);
		}
	}
	
	protected Node createChildNode(Document document,SaturnAttribute attribute) {
		return attribute.creatNode(document, null);
	}
}
